package com.example.activiti.controller;

import java.util.List;

import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.persistence.entity.GroupEntityImpl;
import org.activiti.engine.impl.persistence.entity.UserEntityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.activiti.service.ActivitiUserManageService;

@RestController  
@RequestMapping("/activitiUserController")
public class ActivitiUserController {
	@Autowired
	private ActivitiUserManageService activitiUserManageService;
	
	/**
	 * 根据分组获取用户
	 * @return
	 */
	@PostMapping("/getUserByGroup")
	public List<User> getUserByGroup(String groupId){
		return activitiUserManageService.getUserByGroup(groupId);
	}
	/**
	 * 添加用户
	 * @param user
	 */
	@PostMapping("/addUser")
	void addUser(@RequestBody UserEntityImpl user) {
		activitiUserManageService.addUser(user);
	}
	
	/**
	 * 获取所有的分组
	 * @return
	 */
	@PostMapping("/getAllGroup")
	public List<Group> getAllGroup(){
		return activitiUserManageService.getAllGroup();
	}
	
	/**
	 * 添加分组
	 * @param group
	 */
	@PostMapping("/addGroup")
	public void addGroup(@RequestBody GroupEntityImpl group) {
		activitiUserManageService.addGroup(group);
	}
	
	/**
	 * 添加用户和分组的关系
	 * @param groupId
	 * @param userId
	 */
	@PostMapping("/addRelationGroupUser")
	public void addRelateGroupUser(@RequestParam("groupId")String groupId, @RequestParam("userId")String userId) {
		activitiUserManageService.addRelateGroupUser(groupId, userId);
	}
}
